package com.woniuxy.woniuticket.movieinfomodule.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by 赵晓东 on 2019/6/18/018.
 */
@Component
public class LoginInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String uri = request.getRequestURI();
        if(uri.endsWith("userorder")||
                uri.endsWith("userorder.html")||
                uri.endsWith("ceateOrder")||
                uri.endsWith("getOrderInfo")||
                uri.endsWith("payOrder")||
                uri.endsWith("findAllOrderByUid")||
                uri.endsWith("waitpaying.html")||
                uri.endsWith("choose_seat.html")||
                uri.endsWith("buy_vip1.html")) {
            //如果登陆了就放行
            //获取session,判断是否登陆
            HttpSession session = request.getSession();
            Object obj = session.getAttribute("user");
            if(obj!=null){
                return true;
            }else {
                response.sendRedirect(request.getContextPath()+"/movieshow/login");
                return false;
            }
        }

        return true;
    }
}
